<template>
    <div class="node-container" :style="{ height: containerHeight + 'px' }">
        <NodeContainer :title="data.typeName" :icon="data.icon" :has-more-options="false" v-bind="$attrs">
        </NodeContainer>

        <Handle id="target-a" type="target" :position="Position.Left" />
        <Handle v-for="(item, index) in data.conditions" key="${ item.id } - ${ index }" :id="item.id" type="source"
            :position="Position.Right" :style="{ top: `${50 + index * 30}px` }">
            <div class="handle-content">
                <p>{{ item.name }}</p>
            </div>
        </Handle>
    </div>
</template>

<script setup lang="ts" name="BranchNode">
import { computed } from "vue";
import { Handle, Position, useVueFlow } from "@vue-flow/core";
import NodeContainer from "../node_container.vue";

const props = defineProps({
    id: {
        type: String,
        required: true,
    },
    data: {
        type: Object,
        required: true,
    },
    selected: {
        type: Boolean,
        default: false,
    },
    dragging: {
        type: Boolean,
        default: false,
    },
});

const containerHeight = computed(() => {
    // 基础高度 + 每个条件30px（因为handle间隔30px）
    return 50 + (props.data.conditions?.length || 0) * 30;
});
</script>

<style scoped>
@import "@/assets/handle.css";

.node-content {
    padding: 10px;
    flex-grow: 1;
    height: 100px;
    background-color: #f5f7fa;
}

.handle-content {
    position: absolute;
    white-space: nowrap;
    /* 防止换行 */
    font-size: 12px;
    /* 文本大小 */
    font-weight: bolder;
    color: #555;
    /* 文本颜色 */
    pointer-events: none;
    /* 禁用事件 */

    /* 统一左侧定位规则 */
    right: calc(100% + 5px);
    /* 位于handle左侧5px处 */
    top: 50%;
    /* 垂直居中 */
    transform: translateY(-50%);
    /* 精确居中 */
}
</style>
